package main

import (
	"my_crud_project/controller"
	"my_crud_project/repository"
	"os"
)
import "github.com/gin-gonic/gin"

func main() {
	if err := repository.Init(); err != nil {
		os.Exit(1)
	}
	router := gin.Default()

	router.GET("/community/page/get/:id", func(c *gin.Context) {
		topicId := c.Param("id")
		data := controller.QueryPageInfo(topicId)
		c.JSON(200, data)
	})
	router.POST("/community/publish/post", func(c *gin.Context) {

		topicIdStr, _ := c.GetPostForm("topicIdStr")
		userIdStr, _ := c.GetPostForm("userIdStr")
		content, _ := c.GetPostForm("content")

		data := controller.PublishPost(topicIdStr, userIdStr, content)
		c.JSON(200, data)
	})

	err := router.Run(":9999") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
	if err != nil {
		panic(err)
		return
	}
}
